import numpy as np
from PIL import ImageFont, ImageDraw, Image
import cv2
import time

font_path = "./font/simsun.ttc"

## Make canvas and set the color
def write_pil(name, file_name):
    write_height = 35
    write_width = len(name) * 35
    b, g, r, a = 255, 255, 255, 0
    im = np.zeros((write_height, write_width, 3), 'uint8')

    font = ImageFont.truetype(font_path, 32)

    t1 = time.time()
    ## Use simsum.ttc to write Chinese.
    img_pil = Image.fromarray(im)
    draw = ImageDraw.Draw(img_pil)
    draw.text((1, 1), name, font=font, fill=(b, g, r, a))
    img = np.array(img_pil)

    print((time.time() - t1))

    cv2.imwrite('./faces_db/names/' + file_name + ".jpg", img)



name_list = ['于文清', '于玉洁', '何忠江', '朱嘉皓', '李加微', '李锡蒙', '杜宝琛', '杨博文', '牛佩晴', '王岩', '王帅', '王新宇', '袁国浈', '黄喆']
file_name_list = ['yuwenqing', 'yuyujie', 'hezhongjiang', 'zhujiahao', 'lijiawei', 'liximeng', 'dubaochen', 'yangbowen',
                  'niupeiqing', 'wangyan', 'wangshuai', 'wangxinyu', 'yuanguozhen', 'huangzhe']
for i in range(len(name_list)):
    write_pil(name_list[i], file_name_list[i])